#ifndef _IM_SERVER_SHOP_INFO_CACHE_H_
#define _IM_SERVER_SHOP_INFO_CACHE_H_

#include <stdint.h>
#include <string>
#include <set>
#include <vector>
#include <boost/thread/shared_mutex.hpp>

namespace base {
class SimpleConnectionPool;
};

namespace imserver {

struct ShopInfo {
  int64_t qid;
  std::string shop_name;
  std::string phone;
  std::string address;

  std::string city_code;
  std::string area_code;
  std::string quan_code;
};

class ShopInfoCache {
public:
  static ShopInfoCache & Instance() {
    static ShopInfoCache cache;
    return cache;
  }

  int Reload();
  bool Contains(int64_t uid) const;
  ShopInfo Get(int64_t uid) const;
  void RandomGetShops(size_t limit, std::vector<int64_t> * ret) const;
private:
  ShopInfoCache();

  ShopInfoCache(const ShopInfoCache &);
  ShopInfoCache& operator=(const ShopInfoCache&);

  base::SimpleConnectionPool * db_conn_pool_;

  std::vector<int64_t> shop_vector_;
  mutable boost::shared_mutex vector_mutex_;

  std::map<int64_t, ShopInfo> shops_;
  mutable boost::shared_mutex mutex_;
};

}

#endif // _IM_SERVER_SHOP_INFO_CACHE_H_
